package cn.xscrum.vtsp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.vtsp.domain.VtspDuties;
import cn.xscrum.vtsp.service.IVtspDutiesService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 职务信息Controller
 * 
 * @author xscrum
 * @date 2021-10-01
 */
@Controller
@RequestMapping("/vtsp/duties")
public class VtspDutiesController extends BaseController
{
    private String prefix = "vtsp/duties";

    @Autowired
    private IVtspDutiesService vtspDutiesService;

    @RequiresPermissions("vtsp:duties:view")
    @GetMapping()
    public String duties()
    {
        return prefix + "/duties";
    }

    /**
	 * 查询职务信息列表
     */
    @RequiresPermissions("vtsp:duties:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VtspDuties vtspDuties)
    {
        startPage();
        List<VtspDuties> list = vtspDutiesService.selectVtspDutiesList(vtspDuties);
        return getDataTable(list);
    }

    /**
	 * 导出职务信息列表
     */
    @RequiresPermissions("vtsp:duties:export")
    @Log(title = "职务信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VtspDuties vtspDuties)
    {
        List<VtspDuties> list = vtspDutiesService.selectVtspDutiesList(vtspDuties);
        ExcelUtil<VtspDuties> util = new ExcelUtil<VtspDuties>(VtspDuties.class);
        return util.exportExcel(list, "duties");
    }

    /**
	 * 新增职务信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存职务信息
     */
    @RequiresPermissions("vtsp:duties:add")
    @Log(title = "职务信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VtspDuties vtspDuties)
    {
        System.out.println("请求了此方法");
        System.out.println("前端传来的参数 --------------" + vtspDuties);
        return toAjax(vtspDutiesService.insertVtspDuties(vtspDuties));
    }

    /**
	 * 修改职务信息
     */
    @GetMapping("/edit/{dutiesId}")
    public String edit(@PathVariable("dutiesId") Long dutiesId, ModelMap mmap)
    {
        VtspDuties vtspDuties = vtspDutiesService.selectVtspDutiesById(dutiesId);
        mmap.put("vtspDuties", vtspDuties);
        return prefix + "/edit";
    }

    /**
	 * 修改保存职务信息
     */
    @RequiresPermissions("vtsp:duties:edit")
    @Log(title = "职务信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VtspDuties vtspDuties)
    {
        System.out.println("请求了此方法");
        System.out.println("前端传来的参数 --------------" + vtspDuties);
        return toAjax(vtspDutiesService.updateVtspDuties(vtspDuties));
    }

    /**
	 * 删除职务信息
     */
    @RequiresPermissions("vtsp:duties:remove")
    @Log(title = "职务信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        System.out.println("请求了此方法");
        System.out.println("前端传来的参数 --------------" + ids);
        return toAjax(vtspDutiesService.deleteVtspDutiesByIds(ids));
    }
}
